﻿using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform;
using MiniFox.Platform.Applications;
using MiniFox.Platform.Applications.Auth;
using Platform.Core.Models;
using Platform.Core.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;

namespace Platform.Core.Services
{
    /// <summary>
    /// 
    /// </summary>
    public class PortletService : ApiServiceBase, IPortletService
    {
        [AutoWired]
        protected IPortletProvider Provider { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="principal"></param>
        public PortletService(SystemPrincipal principal) : base(principal)
        {

        }

        public virtual object[] GetMyWidgets()
        {
            return Provider.GetMyWidgets(Principal);
        }

        public ResultObject<ViewTable> Query(PagedQueryObject<WidgetQuery> request)
        {
            request.SortField = "PublishTime";
            request.SortDesc = true;
            var resultSet = Provider.Query(Principal, request);
            var response = resultSet.GetTableResultObject();
            return response;
        }

        public object[] Save(string[] widgets)
        {
            return Provider.Save(Principal, widgets);
        }
    }
}
